<template>
  <a-drawer width="35%" :label-col="4" :wrapper-col="14" :visible="open" @close="onClose">
    <a-divider orientation="left">
      <b>{{ formTitle }}</b>
    </a-divider>
    <a-form-model ref="form" :model="form" :rules="rules">
      <a-form-model-item label="状态" prop="status" >
        <a-select placeholder="请选择状态" v-model="form.status">
          <a-select-option v-for="(d, index) in statusOptions" :key="index" :value="d.value" >{{ d.label }}</a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="删除标志" prop="delFlag" v-if="formType === 1">
        <a-input v-model="form.delFlag" placeholder="请输入删除标志" />
      </a-form-model-item>
      <a-form-model-item label="店铺名称" prop="storeName" >
        <a-input v-model="form.storeName" placeholder="请输入店铺名称" />
      </a-form-model-item>
      <a-form-model-item label="店长名称" prop="storeLeader" >
        <a-input v-model="form.storeLeader" placeholder="请输入店长名称" />
      </a-form-model-item>
      <a-form-model-item label="店长手机号" prop="storeLeaderPhone" >
        <a-input v-model="form.storeLeaderPhone" placeholder="请输入店长手机号" />
      </a-form-model-item>
      <a-form-model-item label="店长id" prop="storeLeaderId" >
        <a-input v-model="form.storeLeaderId" placeholder="请输入店长id" />
      </a-form-model-item>
      <a-form-model-item label="店长头像" prop="storeLeaderImg" >
        <a-input v-model="form.storeLeaderImg" placeholder="请输入店长头像" />
      </a-form-model-item>
      <a-form-model-item label="店铺图片" prop="storeImg" >
        <a-input v-model="form.storeImg" placeholder="请输入店铺图片" />
      </a-form-model-item>
      <a-form-model-item label="店铺公告" prop="storeNotice" >
        <a-input v-model="form.storeNotice" placeholder="请输入店铺公告" />
      </a-form-model-item>
      <a-form-model-item label="提现状态" prop="withdrawalStatus" >
        <a-select placeholder="请选择提现状态" v-model="form.withdrawalStatus">
          <a-select-option v-for="(d, index) in withdrawalStatusOptions" :key="index" :value="d.value" >{{ d.label }}</a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="提现最大金额" prop="maxWithdrawalAmount" >
        <a-input v-model="form.maxWithdrawalAmount" placeholder="请输入提现最大金额" />
      </a-form-model-item>
      <a-form-model-item label="提现最小金额" prop="minWithdrawalAmount" >
        <a-input v-model="form.minWithdrawalAmount" placeholder="请输入提现最小金额" />
      </a-form-model-item>
      <a-form-model-item label="提现备注" prop="withdrawalRemark" >
        <a-input v-model="form.withdrawalRemark" placeholder="请输入内容" type="textarea" allow-clear />
      </a-form-model-item>
      <a-form-model-item label="预约开始时间" prop="reservationStartDate" >
        <a-input v-model="form.reservationStartDate" placeholder="请输入预约开始时间" />
      </a-form-model-item>
      <a-form-model-item label="预约结束时间" prop="reservationEndDate" >
        <a-input v-model="form.reservationEndDate" placeholder="请输入预约结束时间" />
      </a-form-model-item>
      <a-form-model-item label="抢购开始时间" prop="saleStartDate" >
        <a-input v-model="form.saleStartDate" placeholder="请输入抢购开始时间" />
      </a-form-model-item>
      <a-form-model-item label="抢购结束时间" prop="saleEndDate" >
        <a-input v-model="form.saleEndDate" placeholder="请输入抢购结束时间" />
      </a-form-model-item>
      <a-form-model-item label="不交易时间" prop="noPayDay" >
        <a-input v-model="form.noPayDay" placeholder="请输入不交易时间" />
      </a-form-model-item>
      <a-form-model-item label="价格增长比例%" prop="appreciation" >
        <a-input v-model="form.appreciation" placeholder="请输入价格增长比例%" />
      </a-form-model-item>
      <a-form-model-item label="上架费%" prop="listingFee" >
        <a-input v-model="form.listingFee" placeholder="请输入上架费%" />
      </a-form-model-item>
      <a-form-model-item label="直推佣金%" prop="pushFee" >
        <a-input v-model="form.pushFee" placeholder="请输入直推佣金%" />
      </a-form-model-item>
      <a-form-model-item label="好友拼团开关" prop="groupBuying" >
        <a-select placeholder="请选择好友拼团开关" v-model="form.groupBuying">
          <a-select-option v-for="(d, index) in groupBuyingOptions" :key="index" :value="d.value" >{{ d.label }}</a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="分组一名称" prop="groupOneName" >
        <a-input v-model="form.groupOneName" placeholder="请输入分组一名称" />
      </a-form-model-item>
      <a-form-model-item label="分组一图片" prop="groupOneImage" >
        <file-upload v-model="form.groupOneImage" type="image"></file-upload>
      </a-form-model-item>
      <a-form-model-item label="分组一最小单价" prop="groupOneMinPrice" >
        <a-input v-model="form.groupOneMinPrice" placeholder="请输入分组一最小单价" />
      </a-form-model-item>
      <a-form-model-item label="分组一最大单价" prop="groupOneMaxPrice" >
        <a-input v-model="form.groupOneMaxPrice" placeholder="请输入分组一最大单价" />
      </a-form-model-item>
      <a-form-model-item label="分组一商品id" prop="groupOneGoodId" >
        <a-input v-model="form.groupOneGoodId" placeholder="请输入分组一商品id" />
      </a-form-model-item>
      <a-form-model-item label="分组二名称" prop="groupTwoName" >
        <a-input v-model="form.groupTwoName" placeholder="请输入分组二名称" />
      </a-form-model-item>
      <a-form-model-item label="分组二图片" prop="groupTwoImage" >
        <file-upload v-model="form.groupTwoImage" type="image"></file-upload>
      </a-form-model-item>
      <a-form-model-item label="分组二最小单价" prop="groupTwoMinPrice" >
        <a-input v-model="form.groupTwoMinPrice" placeholder="请输入分组二最小单价" />
      </a-form-model-item>
      <a-form-model-item label="分组二最大单价" prop="groupTwoMaxPrice" >
        <a-input v-model="form.groupTwoMaxPrice" placeholder="请输入分组二最大单价" />
      </a-form-model-item>
      <a-form-model-item label="分组二商品id" prop="groupTwoGoodId" >
        <a-input v-model="form.groupTwoGoodId" placeholder="请输入分组二商品id" />
      </a-form-model-item>
      <a-form-model-item label="分组三名称" prop="groupThreeName" >
        <a-input v-model="form.groupThreeName" placeholder="请输入分组三名称" />
      </a-form-model-item>
      <a-form-model-item label="分组三图片" prop="groupThreeImage" >
        <file-upload v-model="form.groupThreeImage" type="image"></file-upload>
      </a-form-model-item>
      <a-form-model-item label="分组三最小单价" prop="groupThreeMinPrice" >
        <a-input v-model="form.groupThreeMinPrice" placeholder="请输入分组三最小单价" />
      </a-form-model-item>
      <a-form-model-item label="分组三最大单价" prop="groupThreeMaxPrice" >
        <a-input v-model="form.groupThreeMaxPrice" placeholder="请输入分组三最大单价" />
      </a-form-model-item>
      <a-form-model-item label="分组三商品id" prop="groupThreeGoodId" >
        <a-input v-model="form.groupThreeGoodId" placeholder="请输入分组三商品id" />
      </a-form-model-item>
      <a-form-model-item label="上级店铺" prop="parentStoreId" >
        <a-input v-model="form.parentStoreId" placeholder="请输入上级店铺" />
      </a-form-model-item>
      <div class="bottom-control">
        <a-space>
          <a-button type="primary" :loading="submitLoading" @click="submitForm">
            保存
          </a-button>
          <a-button type="dashed" @click="cancel">
            取消
          </a-button>
        </a-space>
      </div>
    </a-form-model>
  </a-drawer>
</template>

<script>
import { getQdStore, addQdStore, updateQdStore } from '@/api/system/qdStore'

export default {
  name: 'CreateForm',
  props: {
    statusOptions: {
      type: Array,
      required: true
    },
    withdrawalStatusOptions: {
      type: Array,
      required: true
    },
    groupBuyingOptions: {
      type: Array,
      required: true
    }
  },
  components: {
  },
  data () {
    return {
      submitLoading: false,
      formTitle: '',
      // 表单参数
      form: {
        id: null,

        status: null,

        delFlag: null,

        createBy: null,

        createTime: null,

        updateBy: null,

        updateTime: null,

        storeName: null,

        storeLeader: null,

        storeLeaderPhone: null,

        storeLeaderId: null,

        storeLeaderImg: null,

        storeImg: null,

        storeNotice: null,

        withdrawalStatus: null,

        maxWithdrawalAmount: null,

        minWithdrawalAmount: null,

        withdrawalRemark: null,

        reservationStartDate: null,

        reservationEndDate: null,

        saleStartDate: null,

        saleEndDate: null,

        noPayDay: null,

        appreciation: null,

        listingFee: null,

        pushFee: null,

        groupBuying: null,

        groupOneName: null,

        groupOneImage: null,

        groupOneMinPrice: null,

        groupOneMaxPrice: null,

        groupOneGoodId: null,

        groupTwoName: null,

        groupTwoImage: null,

        groupTwoMinPrice: null,

        groupTwoMaxPrice: null,

        groupTwoGoodId: null,

        groupThreeName: null,

        groupThreeImage: null,

        groupThreeMinPrice: null,

        groupThreeMaxPrice: null,

        groupThreeGoodId: null,

        parentStoreId: null

      },
      // 1增加,2修改
      formType: 1,
      open: false,
      rules: {
      }
    }
  },
  filters: {
  },
  created () {
  },
  computed: {
  },
  watch: {
  },
  mounted () {
  },
  methods: {
    onClose () {
      this.open = false
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset () {
      this.formType = 1
      this.form = {
        id: null,

        status: null,

        delFlag: null,

        createBy: null,

        createTime: null,

        updateBy: null,

        updateTime: null,

        storeName: null,

        storeLeader: null,

        storeLeaderPhone: null,

        storeLeaderId: null,

        storeLeaderImg: null,

        storeImg: null,

        storeNotice: null,

        withdrawalStatus: null,

        maxWithdrawalAmount: null,

        minWithdrawalAmount: null,

        withdrawalRemark: null,

        reservationStartDate: null,

        reservationEndDate: null,

        saleStartDate: null,

        saleEndDate: null,

        noPayDay: null,

        appreciation: null,

        listingFee: null,

        pushFee: null,

        groupBuying: null,

        groupOneName: null,

        groupOneImage: null,

        groupOneMinPrice: null,

        groupOneMaxPrice: null,

        groupOneGoodId: null,

        groupTwoName: null,

        groupTwoImage: null,

        groupTwoMinPrice: null,

        groupTwoMaxPrice: null,

        groupTwoGoodId: null,

        groupThreeName: null,

        groupThreeImage: null,

        groupThreeMinPrice: null,

        groupThreeMaxPrice: null,

        groupThreeGoodId: null,

        parentStoreId: null

      }
    },
    /** 新增按钮操作 */
    handleAdd (row) {
      this.reset()
      this.formType = 1
      this.open = true
      this.formTitle = '添加'
    },
    /** 修改按钮操作 */
    handleUpdate (row, ids) {
      this.reset()
      this.formType = 2
      const id = row ? row.id : ids
      getQdStore(id).then(response => {
        this.form = response.data
        this.open = true
        this.formTitle = '修改'
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.submitLoading = true
          if (this.form.id !== undefined && this.form.id !== null) {
            updateQdStore(this.form).then(response => {
              this.$message.success(
                '修改成功',
                3
              )
              this.open = false
              this.$emit('ok')
            }).finally(() => {
              this.submitLoading = false
            })
          } else {
            addQdStore(this.form).then(response => {
              this.$message.success(
                '新增成功',
                3
              )
              this.open = false
              this.$emit('ok')
            }).finally(() => {
              this.submitLoading = false
            })
          }
        } else {
          return false
        }
      })
    }
  }
}
</script>
